﻿@using Wicresoft.UnifyShow.Utility;
@{
    var planStatus = ViewData["PlanStatus"] as EnumDataSource<EnumUtility.PlanStatus>;
    var taskTypes = ViewData["TaskType"] as EnumDataSource<EnumUtility.TaskType>;
}
<div class="" id="searchContainer" style="height:100%;">
    <div id="searchParam" style="min-height: 64px;">
        <div>
            <div class="left">计划类型</div>
            <div class="right">
                <select data-search-param="TaskType" style="width: 64%;">
                    <option value="-1">全部</option>
                    @{ foreach (var item in taskTypes)
                       {
                        <option value="@item.EnumValue">@item.DisplayValue</option>
                       }
                    }
                </select>
            </div>
        </div>
        <div class="searchForTask">
            <div class="left statusSearch">计划状态</div>
            <div class="right statusSearch">
                <select data-search-param="PlanStatus" style="width: 64%;" id="PlanStatus">
                    <option value="-1">全部</option>
                    @{ foreach (var item in planStatus)
                       {
                        <option value="@item.EnumValue" @(item.EnumValue == (int)EnumUtility.PlanStatus.Started ? "selected='selected'" : "")>@item.DisplayValue</option>
                       }
                    }
                </select>
            </div>
        </div>
        <div>
            <div class="left">创建人</div>
            <div class="right">
                <input type="text" style="width: 60%;" disabled="disabled" data-from="username" data-search-param="CreatorName" />
                <input type="hidden" id="creatorID" data-from="userid" data-search-param="CreatorID" />
                <span class="icon-search" onclick="openResponsibleSearch();"></span>
            </div>
        </div>
        <div>
            <div class="left"></div>
            <div class="right">
                <input type="button" value="搜索" class="searchBtn" onclick="SearchPlan();" />
            </div>
        </div>
    </div>

    <div class="padding5 resultContainer" id="searchedPlanList" style="height:35%;">
        <table id="MySearchedPlanList" fit="true" class="" title="搜索计划结果" pagination="true" url="/PlanManagement/PostSearchPlan"
            fitcolumns="true" singleselect="true">
            <thead>
                <tr>
                    <th field="ID" sortable="true" width="80">计划编号</th>
                    <th field="JobName" sortable="true" width="200">计划名称</th>
                    <th field="JobType" formatter="formatType" sortable="true" width="140">计划类型</th>
                    <th field="Status" formatter="formatPlanStatus_S" width="60">状态</th>
                    <th field="JobOwnerName" width="80" sortable="true">创建人</th>
                    <th field="BeginDate" sortable="true" formatter="DateFormate" width="90">开始时间</th>
                    <th field="EndDate" sortable="true" formatter="DateFormate" width="90">结束时间</th>
                </tr>
            </thead>
        </table>
    </div>
    <div class="padding5 resultContainer" id="relatedTaskList" style="display: none;height:35%;">
        <table id="MyRelatedTaskList" fit="true" class="" title="计划的任务列表" pagination="true" url="/PlanManagement/GetRelatedTaskList"
            fitcolumns="true" singleselect="true">
            <thead>
                <tr>
                    <th field="JobNo" sortable="true" width="120">任务编号</th>
                    <th field="TaskName" sortable="true" width="140">任务名称</th>
                    <th field="Status" formatter="formatStatus" sortable="true" width="80">任务状态</th>
                    <th field="OwnerName" sortable="true" width="80">责任人</th>
                    <th field="BeginDate" sortable="true" formatter="DateFormate" width="90">触发时间</th>
                    <th field="CompleteTime" sortable="true" formatter="DateFormate" width="90">完成时间</th>
                    <th field="EndDate" sortable="true" formatter="DateFormate" width="90">过期时间</th>
                    <th field="OverFlag" sortable="true" formatter="OverFlagRender">是否过期</th>
                </tr>
            </thead>
        </table>
    </div>
</div>
<script type="text/javascript">
    var formatPlanStatus_S = function (value, row, index) {
        var statusList = ["已暂停", "已启用", "已结束"];
        return statusList[value * 1];
    };

    var SearchPlan = function () {
        var param = {
            TaskType: $('[data-search-param="TaskType"]').val(),
            CreatorID: $('#creatorID').val(),
            TaskRange: -1,
            PlanStatus: $('#PlanStatus').val()
        };

        $('#MySearchedPlanList').datagrid('load', param);
    };
    $(function () {
        $('#MySearchedPlanList').datagrid({
            pageSize: 5,
            pageList: [5],
            pageNumber: 1,
            queryParams: {
                TaskType: $('[data-search-param="TaskType"]').val(),
                TaskRange: -1,
                CreatorID: $('#creatorID').val(),
                PlanStatus: $('#PlanStatus').val()
            },
            onDblClickRow: function (rowIndex, rowData) {

                var url = "/PlanManagement/";
                var type = rowData["JobType"];
                switch (type * 1) {
                    case 1:
                        url += "RoutineInspection";
                        break;
                    case 2:
                        url += "ThirdPartyInspection";
                        break;
                    case 3:
                        url += "GeneralPlan";
                        break;
                }
                url += "?ID=" + rowData["ID"];
                showModuleDialog(url, 1080);
            },
            onLoadSuccess: function (data) {

                $('.datagrid-btable').find('td').each(function () {
                    $(this).attr('title', $(this).text());
                });

                if (data && data["rows"].length) {
                    $('#searchedPlanList').find('table tr.datagrid-row').first().click();
                }

            },
            //点击计划，在下方显示计划产生的任务列表
            onClickRow: function (rowIndex, rowData) {
                var id = rowData["ID"];
                if (id) {
                    $('#relatedTaskList').show();
                    $('#MyRelatedTaskList').datagrid({
                        pageSize: 5,
                        pageNumber: 1,
                        pageList: [5],
                        queryParams: { planID: id },
                        onLoadSuccess: function (data) {
                            $('.datagrid-btable').find('td').each(function () {
                                $(this).attr('title', $(this).text());
                            });

                            $('#relatedTaskList .panel-title').text('计划' + rowData["ID"] + '的任务列表');
                        },
                        onDblClickRow: function (rowIndex, rowData) {
                            showModuleDialog('/PlanManagement/TaskDetail?UserRole=3&ID=' + rowData["ID"], 1080);
                        }
                    });

                    var p2 = $('#MyRelatedTaskList').datagrid('getPager');
                    $(p2).pagination({
                        beforePageText: '第',
                        afterPageText: '页&nbsp;共&nbsp;{pages}&nbsp;页',
                        displayMsg: '当前显示{from} - {to}&nbsp;条记录&nbsp;共&nbsp;{total}&nbsp;条记录'

                    });
                }
            }
        });

        var p1 = $('#MySearchedPlanList').datagrid('getPager');
        $(p1).pagination({
            beforePageText: '第',
            afterPageText: '页&nbsp;共&nbsp;{pages}&nbsp;页',
            displayMsg: '当前显示{from} - {to}&nbsp;条记录&nbsp;共&nbsp;{total}&nbsp;条记录'

        });
    });
</script>
